package com.luzhikun.xianLiva;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author shkstart
 * @create 2021-03-14 20:34
 */
public class Player {
    //玩家姓名
    private String name;
    //玩家现金
    private double money = 2000;
    //玩家债务
    private double dept = 6000;
    //购买的商品
    private List<PlayProduct> proList = new ArrayList<PlayProduct>();
    //商品容量
    private static int proCapacity = 100;


    public Player(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "玩家姓名：  " + name + "   玩家余额:   " + money +
                "   玩家欠款:  " + Math.floor(dept) +
                "   出租屋容量: " + proCapacity + "\n" + "商品列表" + ProListToString(proList);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }

    public double getDept() {
        return dept;
    }

    public void setDept(double dept) {
        this.dept = dept;
    }

    public List<PlayProduct> getProList() {
        return proList;
    }

    public void setProList(List<PlayProduct> proList) {
        this.proList = proList;
    }

    public int getProCapacity() {
        return proCapacity;
    }

    public void setProCapacity(int proCapacity) {
        Player.proCapacity = proCapacity;
    }

    public String ProListToString(List<PlayProduct> prolist) {
        if (prolist == null) {
            return null;
        }
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < this.getProList().size(); i++) {
            sb.append(i + 1).append("- ").append(this.getProList().get(i).toString()).append("\n");
        }
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Player)) return false;
        Player player = (Player) o;
        return Double.compare(player.getMoney(), getMoney()) == 0 && Double.compare(player.getDept(), getDept()) == 0 && getName().equals(player.getName()) && Objects.equals(getProList(), player.getProList());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName(), getProList());
    }
}
